package com.tanhua.controller;

import com.tanhua.domain.web.ResultInfo;
import com.tanhua.service.AnnouncementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController

@RequestMapping("/announcement")
public class ManageController {

    @Autowired
    private AnnouncementService announcementService;

    @PostMapping("/find")
    public ResponseEntity<Object> showAnnouncement(@RequestBody Map<String,Integer> param){
        Integer page = param.get("current");
        Integer pagesize = param.get("size");
        log.info("--------------------------page = " + page + "-------------------------------------");
        log.info("--------------------------pagesize = " + pagesize + "-------------------------------------");
        if (page == null){
            page = 1;
        }
        if (pagesize == null){
            pagesize = 5;
        }
        return announcementService.findAll(page,pagesize);
    }

    @PostMapping("/save")
    public ResultInfo saveAnnouncement(@RequestBody Map<String,String> param){
        return announcementService.save(param);
    }

    @PostMapping("/update")
    public ResultInfo updateAnnouncement(@RequestBody Map<String,String> param){
        return announcementService.update(param);
    }

    @GetMapping("/delete")
    public ResultInfo deleteAnnouncement(Long id){
        return announcementService.delete(id);
    }

}
